import {
  useMMKVObject as useMMKVObj,
  useMMKVString as useMMKVStr,
  useMMKVBoolean as useMMKVBoo,
  useMMKVNumber as useMMKVNum
} from 'react-native-mmkv';
import {storage} from '@/utils/storage';

export const useMMKVObject = <T extends object>(key: string) => {
  const [value, setValue] = useMMKVObj<T>(key, storage.getInstance()!);
  return [value, setValue] as const;
};
export const useMMKVString = <T extends string>(key: string) => {
  const [value, setValue] = useMMKVStr(key, storage.getInstance()!);
  return [value as T, setValue] as const;
};
export const useMMKVBoolean = (key: string) => {
  const [value, setValue] = useMMKVBoo(key, storage.getInstance()!);
  return [value, setValue] as const;
};
export const useMMKVNumber = (key: string) => {
  const [value, setValue] = useMMKVNum(key, storage.getInstance()!);
  return [value, setValue] as const;
};
